﻿namespace RatingAuthor
{
  public struct AuthorUrl
  {
    public static readonly AuthorUrl Invalid = new AuthorUrl('?', "!inv-lid!");
    public char FirstLetter { get; set; }
    public string Value { get; set; }

    public override string ToString()
    {
      return Effective;
    }
    public AuthorUrl(char firstLetter, string value)
      : this()
    {
      FirstLetter = firstLetter;
      Value = value;
    }

    public string Effective
    {
      get { return FirstLetter.ToString() + '/' + Value + '/'; }
    }

    public bool Equals(AuthorUrl other)
    {
      return other.FirstLetter == FirstLetter && Equals(other.Value, Value);
    }

    public override bool Equals(object obj)
    {
      if (ReferenceEquals(null, obj)) return false;
      if (obj.GetType() != typeof (AuthorUrl)) return false;
      return Equals((AuthorUrl) obj);
    }

    public override int GetHashCode()
    {
      unchecked
      {
        return (FirstLetter.GetHashCode()*397) ^ Value.GetHashCode();
      }
    }

    public static bool operator ==(AuthorUrl left, AuthorUrl right)
    {
      return left.Equals(right);
    }

    public static bool operator !=(AuthorUrl left, AuthorUrl right)
    {
      return !left.Equals(right);
    }
  }
}